package com.levi.test.rpc;

import io.netty.channel.ChannelInitializer;
import io.netty.channel.ChannelPipeline;
import io.netty.channel.socket.SocketChannel;
import io.netty.handler.codec.http.HttpObjectAggregator;
import io.netty.handler.codec.http.HttpServerCodec;
import io.netty.handler.timeout.IdleStateHandler;

import java.util.concurrent.TimeUnit;

import static com.levi.test.constant.ExecuteCommonData.INT1024;

public class RpcServerInitializer extends ChannelInitializer<SocketChannel> {

    @Override
    protected void initChannel(SocketChannel channel) {
        ChannelPipeline pipeline = channel.pipeline();
        pipeline.addLast(new IdleStateHandler(0, 0, 30 * 3, TimeUnit.SECONDS));
        pipeline.addLast(new HttpServerCodec());// http 编解码
        pipeline.addLast(new HttpObjectAggregator(5 * INT1024 * INT1024)); // http 消息聚合器                                                                     512*1024为接收的最大contentlength
        pipeline.addLast(new RpcRequestHandler());// 请求处理器
    }
}

